home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / comm / www / YAMMRexxScript.lha / muirexxscripts / SpellChecker.rexx < prev    next >
OS/2 REXX Batch file  |  1997-09-30  |  15KB  |  414 lines

  1. /* Application created by MUIBuild           */
  2. /* You need MuiRexx to run these scripts.    */
  3. /* ***************************************** */
  4. /* A YAM arexx script that will spell check  */
  5. /* a Yam selected email. You can also spell  */
  6. /* check for words. You will need AlphaSpell */
  7. /* to do the SpellChecking.                  */
  8. /* ***************************************** */
  9. /*
  10. $VER: 0.7 Copyright ©1997 by Frank Lahr
  11. $AUTHOR: Frank Lahr
  12. $DESCRIPTION: A Spell Checker for Yam using AlphaSpell.
  13. */
  14. options results
  15. options failat 21
  16.  
  17. comm=''
  18. subr=''
  19.  
  20. parse arg comm subr
  21.  
  22. Application_AboutMUI =              0x8042d21d
  23. Application_OpenConfigWindow =      0x804299ba
  24. MUIA_Application_Author =           0x80424842
  25. MUIA_Application_Base =             0x8042e07a
  26. MUIA_Application_Copyright=         0x8042ef4d
  27. MUIA_Application_Description=       0x80421fc6
  28. MUIA_Application_Title =            0x804281b8
  29. MUIA_Application_Version =          0x8042b33f
  30. MUIA_Menuitem_Shortcut =            0x80422030
  31. MUIA_Menuitem_Title =               0x804218be
  32. MUIA_Window_CloseGadget =           0x8042a110
  33. MUIA_Window_DepthGadget =           0x80421923
  34. MUIA_Window_DragBar =               0x8042045d
  35. MUIA_Window_PublicScreen =          0x804278e4
  36. MUIA_Window_SizeGadget =            0x8042e33d
  37. MUIA_List_Active =                  0x8042391c
  38. MUIA_List_Entries =                 0x80421654
  39. MUIA_HorizWeight =                  0x80426db9
  40. MUIA_VertWeight =                   0x804298d0
  41. MUIA_Disabled =                     0x80423661
  42.  
  43. MUIV_List_Active_Top = -2
  44. FALSE = 2
  45. TRUE = 1
  46. dpos=0                                  /* Muirexx lister position */
  47. theword=''                              /* Muirexx lister selected line */
  48. txmsg=''                                /* About window text string definition */
  49. yam_mail=''                             /* Selected Yam email */
  50. yam_screen='Workbench'                  /* Yam screen */
  51. err.title='ERROR:'                      /* Muirexx var defining title of error window */
  52. errmsg=''                               /* Muirexx var defining body of error window */
  53. nc='\033n\033c'                         /* Muirexx var defining a text command, newline and center */
  54. nl='\n'                                 /* Muirexx var defining a text command, newline */
  55. nl2='\n\n'                              /* Muirexx var defining a text command, double newline */
  56. ct='\033c'                              /* Muirexx var defining a text command, center txt */
  57. maxl=4                                  /* Maxium word length without being spelled checked */
  58. as_found=''                             /* Used as a char read in ENV:found, 1=word found, 0=word not found */
  59. pathtodict='PATH AlphaSpell:Dict/'      /* Path to AlphaSpells dictionaries */
  60. asdicts='English.a#? ukacd.a#?'         /* The AlphaSpells dictionaries that will be used, wildcarded so it will use all 8 dicts */
  61. swait='2 SECS'                          /* Short wait while AlphaSpell does it thing */
  62. lwait='5 SECS'                          /* A longer wait while AlphaSpell does it thing */
  63. checkdoc='Ram:checkdoc.temp'            /* Temporary output file from AlphaSpell */
  64. matchdoc='Ram:matchdoc.temp'            /* Temporary output file from AlphaSpell */
  65.  
  66. address YAMSPELL
  67.  
  68. call GetYamInfo
  69.  
  70. select
  71.      when comm = '' then do
  72.           call InitialGui
  73.      end
  74.      when comm = 'SCWORD' then call WordGui
  75.      when comm = 'SCDOC' then do
  76.           if open('infile', yam_mail,'R') then do
  77.                address command 'run >NIL: AlphaSpell:AlphaSpell CHECK FROM 'yam_mail' TO ram:checkdoc.temp 'pathtodict' 'asdicts
  78.                call DocGui
  79.                address command 'c:wait 'swait
  80.                call open('asdoc',checkdoc,'R')
  81.                call seek('asdoc',0,'B')
  82.                do until eof('asdoc')
  83.                     theword = readln('asdoc')
  84.                     if length(theword) >= maxl then do
  85.                          if verify(theword,'0123456789','m') = 0 then do
  86.                               list ID YSCW MUIA_List_Active MUIV_List_Active_Top
  87.                               list ID YSCW NODUP POS dpos STRING theword 
  88.                               dpos=dpos+1
  89.                          end
  90.                          text ID YSCCT LABEL ct || dpos || " unknown words."
  91.                     end
  92.                end
  93.           end
  94.           else do
  95.                errmsg='You must select a Yam email first.'
  96.                call ErrorMsg
  97.           end
  98.      end
  99.      when comm = 'CHECKWORD' then do
  100.           text ID YSCCT LABEL ct||"Checking the spellng..."
  101.           string ID YSCW
  102.           theword = result
  103.           call SpellCheckTheWord
  104.      end
  105.      when comm = 'GETALTER' then do
  106.           theword = subr
  107.           call SpellCheckTheWord
  108.      end
  109.      when comm = 'ABOUT' then call AboutProgs
  110.      when comm = 'QUIT' then call QuitSpellChecker
  111.      otherwise do
  112.           errmsg = "This command is not recognized.\n" comm
  113.           call ErrorMsg
  114.      end
  115. end
  116.  
  117. exit
  118.  
  119. /* ******************************* */
  120. /* Build the MuiRexx gui interface */
  121. /* ******************************* */
  122.  
  123. InitialGui:
  124.  
  125. window ID MINI COMMAND """quit""" PORT YAMSPELL TITLE """Yam SpellChecker""" ATTRS MUIA_Window_CloseGadget TRUE MUIA_Window_PublicScreen yam_screen
  126.      group HORIZ FRAME LABEL "SpellCheck..."
  127.           button PRESS COMMAND """SpellChecker.rexx SCWORD""" LABEL "Word"
  128.           button PRESS COMMAND """SpellChecker.rexx SCDOC""" LABEL "Document"
  129.      endgroup
  130.      group
  131.           button PRESS COMMAND """quit""" PORT YAMSPELL LABEL "Quit"
  132.      endgroup
  133. endwindow
  134.  
  135. return
  136.  
  137. /* *********************** */
  138. /* *********************** */
  139.  
  140. DocGui:
  141.  
  142. window ID MINI close
  143. window ID DWIN COMMAND """SpellChecker.rexx QUIT""" TITLE """Yam Document SpellChecker""" ATTRS MUIA_Window_CloseGadget TRUE MUIA_Window_PublicScreen yam_screen
  144.      menu LABEL "Project "
  145.           menu LABEL "About..."
  146.                item COMMAND """SpellChecker.rexx ABOUT YAMSPELLCHECKER""" LABEL "SpellChecker "
  147.                item COMMAND """SpellChecker.rexx ABOUT YAM""" LABEL "Yam "
  148.                item COMMAND """SpellChecker.rexx ABOUT ALPHASPELL""" LABEL "AlphaSpell "
  149.                item COMMAND """SpellChecker.rexx ABOUT MUIREXX""" LABEL "MuiRexx"
  150.                item COMMAND '"method 'Application_AboutMUI' 0"' PORT YAMSPELL LABEL "MUI"
  151.           endmenu
  152.           menu LABEL "Settings"
  153.                item COMMAND '"method 'Application_OpenConfigWindow'"' PORT YAMSPELL LABEL "MUI..."
  154.           endmenu
  155.           item ATTRS MUIA_Menuitem_Title '-1'
  156.           item COMMAND """quit""" PORT YAMSPELL ATTRS MUIA_Menuitem_Shortcut 'Q' LABEL "Quit"
  157.      endmenu
  158.      menu LABEL "Rexx  "
  159.           item COMMAND '"SpellChecker.rexx SCDOC"' ATTRS MUIA_Menuitem_Shortcut 'C' LABEL "Check Document "
  160.      endmenu
  161.      group
  162.           group 
  163.                group FRAME LABELS "Words:"
  164.                     list ID YSCW PRESS COMMAND """SpellChecker.rexx GETALTER %s"""
  165.                     text ID YSCCT
  166.                endgroup
  167.                group FRAME LABELS "Alternatives:"
  168.                     list ID YSCL
  169.                endgroup
  170.           endgroup
  171.           group HORIZ
  172.                button PRESS COMMAND """SpellChecker.rexx QUIT""" LABEL "Quit"
  173.           endgroup
  174.      endgroup
  175. endwindow
  176.  
  177. return
  178.  
  179. /* ********************* */
  180. /* ********************* */
  181.  
  182. WordGui:
  183.  
  184. call open('asfound','ENV:found','W')
  185. call writeln('asfound','1')
  186. call close('asfound')
  187. window ID MINI close
  188. window ID WWIN COMMAND """SpellChecker.rexx QUIT""" TITLE """Yam Word SpellChecker""" ATTRS MUIA_Window_CloseGadget TRUE MUIA_Window_PublicScreen yam_screen
  189.      menu LABEL "Project "
  190.           menu LABEL "About..."
  191.                item COMMAND '"SpellChecker.rexx ABOUT YAMSPELLCHECKER"' LABEL "SpellChecker "
  192.                item COMMAND '"SpellChecker.rexx ABOUT YAM"' LABEL "Yam "
  193.                item COMMAND '"SpellChecker.rexx ABOUT ALPHASPELL"' LABEL "AlphaSpell "
  194.                item COMMAND '"SpellChecker.rexx ABOUT MUIREXX"' LABEL "MuiRexx"
  195.                item COMMAND '"method 'Application_AboutMUI' 0"' PORT YAMSPELL LABEL "MUI"
  196.           endmenu
  197.           menu LABEL "Settings"
  198.                item COMMAND '"method 'Application_OpenConfigWindow'"' PORT YAMSPELL LABEL "MUI..."
  199.           endmenu
  200.           item ATTRS MUIA_Menuitem_Title '-1'
  201.           item COMMAND """quit""" PORT YAMSPELL ATTRS MUIA_Menuitem_Shortcut 'Q' LABEL "Quit"
  202.      endmenu
  203.      menu LABEL "Rexx "
  204.           item COMMAND '"SpellChecker.rexx CHECKWORD"' ATTRS MUIA_Menuitem_Shortcut 'C' LABEL "Check Word "
  205.      endmenu
  206.      group
  207.           group 
  208.                group FRAME LABELS "Word:" 
  209.                     string ID YSCW
  210.                     text ID YSCCT
  211.                endgroup
  212.                group LABELS "Alternatives:"
  213.                     list ID YSCL
  214.                endgroup
  215.           endgroup
  216.           group HORIZ
  217.                button PRESS COMMAND """SpellChecker.rexx CHECKWORD""" LABEL "Check"
  218.                button PRESS COMMAND """SpellChecker.rexx QUIT""" LABEL "Quit"
  219.           endgroup
  220.      endgroup
  221. endwindow
  222.  
  223. return
  224.  
  225. /* ************************************************************ */
  226. /* Send TheWord to AlphaSpell to see if it is spelled correctly */
  227. /* ************************************************************ */
  228.  
  229. SpellCheckTheWord:
  230.  
  231. address YAMSPELL
  232. if theword ~= "" then do
  233.      if exists('AlphaSpell:AlphaSpell') then do
  234.           address command 'run >NIL: AlphaSpell:AlphaSpell SEARCH FOR 'theword' 'pathtodict' 'asdicts
  235.           if exists('ENV:found') then do
  236.                address command 'c:wait 'swait
  237.                call open('envvar','ENV:found','R')
  238.                as_found = readch('envvar',1)
  239.                select
  240.                     when as_found = 0 then do
  241.                          txmsg=ct||'Wrong. Or not found.'
  242.                          text ID YSCCT LABEL txmsg
  243.                          address command 'run AlphaSpell:AlphaSpell MATCH ED 2 'theword' TO 'matchdoc' 'pathtodict' 'asdicts 
  244.                          address command 'c:wait 'lwait
  245.                          if exists(matchdoc) then do
  246.                               list ID YSCL STRING ""
  247.                               text ID YSCCT LABEL ct||"Looking for matches..."
  248.                               call open('match',matchdoc,'R')
  249.                               theword = readln('match')
  250.                               if theword = '' then do
  251.                                    text ID YSCCT LABEL ct||"No matches."
  252.                                    exit
  253.                               end
  254.                               call seek('match',0,'B')
  255.                               do until eof('match')
  256.                                    dpos=dpos+1
  257.                                    theword = readln('match')
  258.                                    if length(theword) >= maxl then do
  259.                                         list ID YSCL MUIA_List_Active MUIV_List_Active_Top
  260.                                         list ID YSCL NODUP POS dpos STRING theword 
  261.                                    end
  262.                               end
  263.                               text ID YSCCT LABEL ct||"Done."
  264.                               call close('match')
  265.                          end
  266.                     end
  267.                     when as_found = 1 then do
  268.                          list ID YSCL STRING ""
  269.                          txmsg=ct||'Correct'
  270.                          text ID YSCCT LABEL txmsg
  271.                     end
  272.                     otherwise do
  273.                          errmsg='AlphaSpells ENV:found unidentifiable.'
  274.                          call ErrorMsg
  275.                     end
  276.                end
  277.                Close('envvar')
  278.           end
  279.           else do
  280.                errmsg='AlphaSpell ENV:found does not exist. Retry.'
  281.                call ErrorMsg
  282.           end
  283.      end
  284.      else do
  285.           errmsg='AlphaSpell does not exist.'
  286.           call ErrorMsg
  287.      end
  288. end
  289. else do
  290.      errmsg='No word to check spelling.'
  291.      call ErrorMsg
  292. end
  293.  
  294. return
  295.  
  296. /* *************************************************** */
  297. /* Get the needed Yam info; screen name,selected email */
  298. /* *************************************************** */
  299.  
  300. GetYamInfo:
  301.  
  302.      if ~show('p','YAM') then do
  303.           errmsg = ct||'You need YAM running to use Find Addresses.'
  304.           call ErrorMsg
  305.      end
  306.      Address YAM
  307.      show         
  308.      info SCREEN
  309.      yam_screen = result
  310.      if yam_screen = "" then yam_screen = 'Workbench'
  311.  
  312.      getmailinfo file
  313.      yam_mail = result 
  314.  
  315. return
  316.  
  317. /* ************************** */
  318. /* Basic About requester info */
  319. /* ************************** */
  320.  
  321. AboutProgs:
  322.  
  323.    Address YAM 'info title'
  324.    yamtitle=result 
  325.    Address YAM 'info copyright'
  326.    yamcopy=result
  327.    select
  328.       when subr='YAM' then do
  329.          ab.title="About "yamtitle
  330.          aboutmsg=ct||'  Awesome E-mailer, © Marcel Beck  '         
  331.          Call AboutWin
  332.       end
  333.       when subr='MUIREXX' then do
  334.          ab.title="About Muirexx"
  335.          aboutmsg=ct||"  A great Gui'er :), © Russ Leighton  "
  336.          Call AboutWin
  337.       end
  338.       when subr='ALPHASPELL' then do
  339.           ab.title="About AlphaSpell"
  340.           aboutmsg=ct||'The SpellChecker, © Fergus Duniho  '
  341.           Call AboutWin
  342.       end
  343.       when subr='YAMSPELLCHECKER' then do
  344.          ab.title="About SpellChecker.rexx"
  345.          ab.desc="Yam SpellChecker -- Utility for YAM"
  346.          ab.copy="Version 0.4 Copyright ©1997 by Frank Lahr"
  347.          ab.text1=yamtitle||' '||yamcopy
  348.          ab.text2="MuiRexx © Russell Leighton"
  349.          ab.text3="MUI © Stefan Stuntz"
  350.          ab.text4="YamTools © Dick Whiting for his help"
  351.          ab.text5="AlphaSpell © Fergus Duniho"
  352.          aboutmsg=nc||ab.desc||nl||nc||ab.copy||nl2||ab.text1||nl||ab.text2||nl||ab.text3||nl||ab.text4||nl||ab.text5
  353.          Call AboutWin
  354.       end
  355.       otherwise nop
  356.    end
  357.  
  358. Return
  359.  
  360. /******************************************************************************/
  361. /*  Display window for ABOUT programs.                                        */
  362. /******************************************************************************/
  363.  
  364. AboutWin:
  365.  
  366.      window ID SCABT TITLE '"'ab.title'"' ATTRS MUIA_Window_DepthGadget FALSE,
  367.           MUIA_Window_DragBar FALSE MUIA_Window_PublicScreen yam_screen
  368.           group
  369.                text LABEL aboutmsg
  370.           endgroup
  371.           group HORIZ
  372.                space HORIZ
  373.                button PRESS COMMAND '"window ID SCABT CLOSE"' PORT YAMSPELL LABEL "OK"
  374.                space HORIZ
  375.           endgroup
  376.      endwindow
  377.  
  378. return
  379.  
  380. /* **************************************** */
  381. /* A little cleaning up as we quit the prog */
  382. /* **************************************** */
  383.  
  384. QuitSpellChecker:
  385.  
  386.      address command 'c:delete T:runsc.script QUIET'
  387.      address command 'c:delete Ram:checkdoc.temp QUIET'
  388.      address command 'c:delete Ram:matchdoc.temp QUIET'
  389.      address YAMSPELL
  390.      PORT YAMSPELL 
  391.      quit
  392.  
  393. return
  394.  
  395. /* ************************** */
  396. /* Basic error requester info */
  397. /* ************************** */
  398.  
  399. ErrorMsg:
  400.  
  401.      window ID ERR TITLE '"'err.title'"' PORT YAMSPELL ATTRS MUIA_Window_DepthGadget FALSE,
  402.           MUIA_Window_DragBar FALSE MUIA_Window_PublicScreen yam_screen
  403.           group
  404.                text LABEL errmsg
  405.           endgroup
  406.           group HORIZ
  407.                space HORIZ
  408.                button PRESS COMMAND '"window ID ERR CLOSE"' PORT YAMSPELL LABEL "OK"
  409.                space HORIZ
  410.           endgroup
  411.      endwindow
  412.     
  413. return
  414.